package org.eclipsercp.hyperbola;

import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.util.Assert;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IPersistableElement;
import org.jivesoftware.smack.util.StringUtils;

/**
 * Input for a chat editor.
 */
@SuppressWarnings("deprecation")
public class ChatEditorInput implements IEditorInput {

    private String participant;

    /**
     * Creates a chat editor input on the given session and participant.
     */
    public ChatEditorInput(String participant) {
        Assert.isNotNull(participant);
        this.participant = StringUtils.parseBareAddress(participant);
    }

    public boolean exists() {
        return true;
    }

    public ImageDescriptor getImageDescriptor() {
        return null;
    }

    public String getName() {
        return getParticipant();
    }

    public IPersistableElement getPersistable() {
//         Not persistable between sessions
        return null;
    }

    public String getToolTipText() {
        return "";
    }

    @SuppressWarnings("unchecked")
    public Object getAdapter(Class adapter) {
        return null;
    }

    public boolean equals(Object obj) {
        if (super.equals(obj))
            return true;
        if (!(obj instanceof ChatEditorInput))
            return false;
        ChatEditorInput other = (ChatEditorInput) obj;
        return this.participant.equals(other.participant);
    }

    public int hashCode() {
        return participant.hashCode();
    }

    public String getParticipant() {
        return participant;
    }
}